package cn.tedu.clyback.RolePermission.service;

import cn.tedu.clyback.RolePermission.mapper.RolePermissionMapper;
import cn.tedu.clyback.RolePermission.pojo.vo.RolePermissionVO;
import cn.tedu.clyback.role.mapper.RoleMapper;
import cn.tedu.clyback.role.pojo.dto.RoleSelectParam;
import cn.tedu.clyback.role.pojo.vo.RoleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;

@Slf4j
@Service
public class RolePermissionServiceImpl implements RolePermissionService{

    @Autowired
    RoleMapper roleMapper;
    @Autowired
    RolePermissionMapper rolePermissionMapper;
    @Override
    public void insertPermission(Integer roleId, Integer permissionId) {
        /*log.debug("开始处理【添加用户权限】的业务，参数：{},{}", roleId, permissionId);
        RoleSelectParam roleSelectParam = new RoleSelectParam();
        roleSelectParam.setRoleId(roleId);
        List<RoleVO> list =roleMapper.selectRole(roleSelectParam);
        Integer id = list.get(0).getRoleId();
        log.debug("查询角色id成功，结果：{}", id);
        rolePermissionMapper.insertPermission(roleId,permissionId);*/

        rolePermissionMapper.insertPermission(roleId,permissionId);
    }

    @Override
    public void deleteUserPermission(Integer roleId, Integer permissionId) {
        rolePermissionMapper.deleteUserPermission(roleId,permissionId);
    }

    @Override
    public HashSet<RolePermissionVO> selectUserByRoleId(Integer roleId) {
        HashSet<RolePermissionVO> set = rolePermissionMapper.selectUserByRoleId(roleId);
        return set;
    }

    @Override
    public void deletePermission(Integer roleId, Integer permissionId) {
        rolePermissionMapper.deletePermission(roleId,permissionId);
    }
}
